package openjdk.stream;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Arrays;

public class MapReduce {


    public static void main(String[] args) {


        DecimalFormat df = new DecimalFormat("#,###.00");
        System.out.println(df.format(new BigDecimal(123456.75)));
        System.out.println(df.format(new BigDecimal(123456.00)));
        System.out.println(df.format(new BigDecimal(123456.78)));
        System.out.printf("Get cnt sum: %s",df.format(getSumCnt()));
    }


    private static final BigDecimal getSumCnt(){
        return Arrays.asList(new M("a",BigDecimal.ONE),
                new M("b",BigDecimal.TEN))
                .stream()
                .filter(o->o.getCnt().compareTo(BigDecimal.valueOf(100L))==1)
                .map(o->o.getCnt())
                .reduce(BigDecimal.ZERO,(m,n)->m.add(n));
    }

    static class M{
        String name;
        BigDecimal cnt;

        public M(String name, BigDecimal cnt) {
            this.name = name;
            this.cnt = cnt;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public BigDecimal getCnt() {
            return cnt;
        }

        public void setCnt(BigDecimal cnt) {
            this.cnt = cnt;
        }
    }
}
